from django import newforms as forms
from django.template.defaultfilters import slugify

from bingo.apps import widgets
from bingo.apps.blog.models import Entry
from tagging.models import Tag


mce_settings = {
    'auto_resize': True,
    #'language': 'pt_br',
    'theme': 'advanced',
}

class FormEntry(forms.Form):
    slug = forms.CharField(widget=forms.HiddenInput(), required=False)
    title = forms.CharField(max_length=200)
    body = forms.CharField(widget=widgets.TinyMCE())
    boby.widget.mce_settings = content.widget.update_settings(mce_settings)
    draft = forms.BooleanField(widget=forms.CheckboxInput(), 
                               required=False, initial=False)
    tags = forms.CharField(max_length=100, required=False, initial='geral')

    def save(self, slug=None):
        if slug:
            obj = Entry.objects.get(slug=slug)
        else:
            obj = Entry()
            obj.slug = slugify(obj.title)
            
        obj.title = self.clean_data['title']
        obj.content = self.clean_data['content']
        obj.show_in_blog = self.clean_data['show_in_blog']
        obj.tags = self.clean_data['tags']

        obj.save()

    def delete(self, **kwargs):
        Entry.objects.filter(**kwargs).delete()
